<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var romanToInt = function (s) {
        let n, i, flag;
        let num = 0;
        for (i = 0; i < s.length; i++) {
            if (s[i] == 'I') {
                if (s[i + 1] == 'V') {
                    i += 1;
                    num += 4;
                } else if (s[i + 1] == 'X') {
                    i += 1;
                    num += 9;
                } else {
                    num += 1;
                }
            } else if (s[i] == 'X') {
                if (s[i + 1] == 'L') {
                    i += 1;
                    num += 40;
                } else if (s[i + 1] == 'C') {
                    i += 1;
                    num += 90;
                } else {
                    num += 10;
                }
            } else if (s[i] == 'C') {
                if (s[i + 1] == 'D') {
                    i += 1;
                    num += 400;
                } else if (s[i + 1] == 'M') {
                    i += 1;
                    num += 900;
                } else {
                    num += 100;
                }
            } else if (s[i] == 'V') {
                num += 5;
            } else if (s[i] == 'L') {
                num += 50;
            } else if (s[i] == 'D') {
                num += 500;
            } else if (s[i] == 'M') {
                num += 1000;
            }

        }
        return num;
    };
</script>

</html>